<table width="350" border="3">
  <form  method="post" action='<?php $_SERVER[PHP_SELF]?>'>
  <p>
  <!-- pilih kabupaten yang akan dicari potensi nya -->
   Pilih kabupaten :  <select name="nama_kab" id="nama_kab">
     <option value="- Pilih Kabupaten  -">- Pilih Kabupaten -</option>
      <?php 
		$db = new Rekomendasi();
		$table = "kabkota";
		$order = "idkabkota";
		$id = "";
		$field = "";
		$kabupaten = $db->lihat($table,$id,$field,$order);
		foreach ($kabupaten as $x) {
		   	echo '<option value="'.$x['nama_kabkota'].'">'.$x['nama_kabkota'].'</option>';
		}
        
       ?>
    </select>
  </p>
  <p>&nbsp; </p>
  <!-- pilih kriteria nya -->
<?php
	$db2 = new Rekomendasi();
   	$table2 = "kriteria";
	$order2 = "idkriteria";
	$id2 = "";
	$field2 = "";
	$kriteria = $db->lihat($table2,$id2,$field2,$order2);
	$jumlah = count($kriteria);
    //$ch1='checked';
	if(isset($_POST['submit']))
    {
	    $aform = $_POST['aform'];
		$N = count($aform);


            //echo("<p>You selected $N door(s): ");
     		for($i=1; $i <= $jumlah; $i++)
			{
				//echo($aform[$i] . " ");
				if(!(empty($aform[$i])))
				{
				    $bform[$i]="checked";
				}
				else
				{
				    $bform[$i]="unchecked";
				}
			}
	 		
	 echo ("<tr  class='judultable'><td colspan='2'><div align='center'>Keterangan</div></td></tr>");
	 echo ("<tr  class='isitabel'><td>A1</td><td><div align='left'>Rusunawa / Rusunami</div></td></tr>");
	 echo ("<tr  class='isitabel'><td>A2</td><td><div align='left'>Tempat Pembuangan Sampah Akhir</div></td></tr>");
	 echo ("<tr  class='isitabel'><td>A3</td><td><div align='left'>Ruang Terbuka Hijau</div></td></tr>");
	 echo ("<tr  class='isitabel'><td>A4</td><td><div align='left'>Penampungan Air Bersih</div></td></tr>");
	 echo ("<tr  class='isitabel'><td>A5</td><td><div align='left'>Septicktank Komunal</div></td></tr>");

	 
	}
    $j=1; 
	for($i=1;$i<=$jumlah; $i++){
	               if(!(empty($aform[$i])))
				   {
  											echo "<tr  class='isitabel'><td>K$j</td>
  										              <td><div align='left'>";echo($aform[$i]); 
											         echo"</div></td>
								        	
											</tr>";
											$j++;
					}					
     }
	echo"<td colspan='2'><br></td></tr><tr  class='judultable'><td colspan='2'><div align='center'>Pilih Kriteria</div></td></tr>";
	 
	$i=1;
	foreach ($kriteria as $data){
  			echo "<tr class='isitabel'><td width='5%'><input type='checkbox'  name= 'aform[$i]' value='$data[nama_kriteria]' $bform[$i]></td>
  					<td  class='isitabel'><div align='left'>$data[nama_kriteria]</div></td>
				  </tr>";$i++;
	}
?>

<tr><td colspan="2"><div align="right"><input type="submit" value="Pilih" name="submit"> 
      <input type="reset" value="Reset" onClick="javascript:history.back()" /></div>
</td></tr>

</table>

</td>
</tr>
</table>

<?php if($N!=0) {
// isi rasio 
echo ("<div><br>Bandingkan Masing-Masing Kriteria yang telah dipilih : <br><br></div>");
?>
<table border="5">
<tr class="judultable">
<td></td>
<?php
$kriteria=1;
for($i=1;$i <= $N;$i++)
{
    while(empty($aform[$kriteria]))
		   {
		       $kriteria++;
			   
		   }
		 
		       echo ("<td>".$aform[$kriteria]); 
			   $kriteria++;?></td>

<!-- ngisi tabel perbandingan sesuai yg dipilih berdasarkan kriteria-->

<?php
}
echo"</tr>";
$kriteria=1;
for($i=1;$i <= $N;$i++)
{ ?> 

<tr  class='isitabel'><td><?php 
          
		  while(empty($aform[$kriteria]))
		   {
		       $kriteria++;
			   
		   }
		 
		       echo ($aform[$kriteria]); 
			   $kriteria++;
			   for($j=1;$j<=$N;$j++)
			         {
			       $vari=$_POST['isi'];
			   ?></td>
			   <td width="50"><?php if (($i==$j)or ($i>1 and $j==1) or ($i>=3 and $j==2)or ($i>=4 and $j==3))
			   {
			   }
			   else
			   {
			   echo"<select name='isi[$i][$j]'";  
			   //echo "disabled='disabled'"; 
			   echo" >";
			   
			   } ?>
               
                <option value="1" <?php if ($vari[$i][$j]==1) { echo"selected='selected'"; } ?> > <?php echo"Sama-sama penting"; ?>
				<option value="3" <?php if ($vari[$i][$j]==3) { echo"selected='selected'"; } ?> > <?php echo"Sedikit lebih penting"; ?>
				<option value="5" <?php if ($vari[$i][$j]==5) { echo"selected='selected'"; } ?> > <?php echo" Lebih penting"; ?>
				<option value="7" <?php if ($vari[$i][$j]==7) { echo"selected='selected'"; } ?> > <?php echo"Sangat penting"; ?>
				<option value="9" <?php if ($vari[$i][$j]==9) { echo"selected='selected'"; } ?> > <?php echo"Mutlak pentingya"; ?>
			
				</td>
			<?php } ?><!-- endfor j-->
</tr>

<!-- end rasio -->
<?php } echo"</table>";}//end n!=0?>

<?php



//isi bobot alternatif menurut kriteria


if($N!=0)
{
echo ("<br>Bandingkan Masing-Masing Alternatif : <br><br>");
$alf=$_POST['af'];
$kriteria=1;
?>
<!--isi alternatif -->
<table border="5">
<?php
$kriteria=1;
for($i=1;$i <= $N;$i++)
{ $vartm=$_POST['altm'];
  $varj=$_POST['altj'];
  $vartk=$_POST['alttk'];
  $vartp=$_POST['alttp'];
  $isii=$i;
?> 

<tr><td colspan="5" align="center">Menurut <?php 
          
		  while(empty($aform[$kriteria]))
		   {
		       $kriteria++;
			   
		   }
		 
		       echo ($aform[$kriteria]); 
			   $kriteria++;?>
			   </td></tr>
		   
			   <tr class="judultable"><td><br></td><td>Rusunawa / Rusunami</td><td>Tempat Pembuangan Sampah Akhir</td><td>Ruang Terbuka Hijau</td><td>Penampungan Air Bersih</td><td>Septicktank Komunal</td></tr>
			   <tr  class='isitabel'><td>Rusunawa / Rusunami</td>
			   <?php
			   
			   for($j=1;$j<=4;$j++)
			         { ?>
			   <td>
			  <?php if ($j==1)
			  {
			  }
			  else
			  {
				  echo"<select name='altm[$i][$j]'"; //if ($j==1)
			   //echo "disabled='disabled'"; 
			   echo" >"; 
			   }
			   ?>
               
                <option value="1" <?php if ($vartm[$i][$j]==1) { echo"selected='selected'"; } ?> > <?php echo"Sama-sama penting"; ?>
				<option value="3" <?php if ($vartm[$i][$j]==3) { echo"selected='selected'"; } ?> > <?php echo"Sedikit lebih penting"; ?>
				<option value="5" <?php if ($vartm[$i][$j]==5) { echo"selected='selected'"; } ?> > <?php echo" Lebih penting"; ?>
				<option value="7" <?php if ($vartm[$i][$j]==7) { echo"selected='selected'"; } ?> > <?php echo"Sangat penting"; ?>
				<option value="9" <?php if ($vartm[$i][$j]==9) { echo"selected='selected'"; } ?> > <?php echo"Mutlak pentingya"; ?>
				</td>
				<?php } //end for j ?>
              </tr>
			  <tr  class='isitabel'><td>Tempat Pembuangan Sampah Akhir</td>
			   <?php 
			   for($j=1;$j<=4;$j++)
			         { ?>
			   <td >
			  <?php if ($j<3)
			  {
			  }
			  else
			  {
				  echo"<select name='alttp[$i][$j]'";
			   //echo "disabled='disabled'"; 
			   echo" >"; 
			   }
			   ?>
               
                <option value="1" <?php if ($vartp[$i][$j]==1) { echo"selected='selected'"; } ?> > <?php echo"Sama-sama penting"; ?>
				<option value="3" <?php if ($vartp[$i][$j]==3) { echo"selected='selected'"; } ?> > <?php echo"Sedikit lebih penting"; ?>
				<option value="5" <?php if ($vartp[$i][$j]==5) { echo"selected='selected'"; } ?> > <?php echo" Lebih penting"; ?>
				<option value="7" <?php if ($vartp[$i][$j]==7) { echo"selected='selected'"; } ?> > <?php echo"Sangat penting"; ?>
				<option value="9" <?php if ($vartp[$i][$j]==9) { echo"selected='selected'"; } ?> > <?php echo"Mutlak pentingya"; ?>
				</td>
				<?php } //end for j ?>
              </tr>
			  <tr  class='isitabel'><td>Ruang Terbuka Hijau</td>
			  <?php
			
			   for($j=1;$j<=4;$j++)
			         { ?>
			   <td>
			  <?php if ($j<4)
			  {
			  }
			  else
			  {
				  echo"<select name='altj[$i][$j]'";
			   //echo "disabled='disabled'"; 
			   echo" >"; 
			   }
			   ?>
               
                <option value="1" <?php if ($varj[$i][$j]==1) { echo"selected='selected'"; } ?> > <?php echo"Sama-sama penting"; ?>
				<option value="3" <?php if ($varj[$i][$j]==3) { echo"selected='selected'"; } ?> > <?php echo"Sedikit lebih penting"; ?>
				<option value="5" <?php if ($varj[$i][$j]==5) { echo"selected='selected'"; } ?> > <?php echo" Lebih penting"; ?>
				<option value="7" <?php if ($varj[$i][$j]==7) { echo"selected='selected'"; } ?> > <?php echo"Sangat penting"; ?>
				<option value="9" <?php if ($varj[$i][$j]==9) { echo"selected='selected'"; } ?> > <?php echo"Mutlak pentingya"; ?>
				</td>
				<?php }//end for j ?>
              </tr>
			  <tr  class='isitabel'><td>Penampungan Air Bersih</td>
			   <?php
	
			   for($j=1;$j<=4;$j++)
			         { ?>
			   <td>
			  <?php if ($j<5) 
			  {
			  }
			  else
			  {
				  echo"<select name='alttk[$i][$j]'";
			   //echo "disabled='disabled'"; 
			   echo" >"; 
			   }
			   ?>
               
                <option value="1" <?php if ($vartk[$i][$j]==1) { echo"selected='selected'"; } ?> > <?php echo"Sama-sama penting"; ?>
				<option value="3" <?php if ($vartk[$i][$j]==3) { echo"selected='selected'"; } ?> > <?php echo"Sedikit lebih penting"; ?>
				<option value="5" <?php if ($vartk[$i][$j]==5) { echo"selected='selected'"; } ?> > <?php echo" Lebih penting"; ?>
				<option value="7" <?php if ($vartk[$i][$j]==7) { echo"selected='selected'"; } ?> > <?php echo"Sangat penting"; ?>
				<option value="9" <?php if ($vartk[$i][$j]==9) { echo"selected='selected'"; } ?> > <?php echo"Mutlak pentingya"; ?>
				</td>
				<?php } //end for j ?>
              </tr>
			  
			  <tr  class='isitabel'><td>Septicktank Komunal</td>
			   <?php
	
			   for($j=1;$j<=4;$j++)
			         { ?>
			   <td>
			  <?php if ($j<6) 
			  {
			  }
			  else
			  {
				  echo"<select name='alttk[$i][$j]'";
			   //echo "disabled='disabled'"; 
			   echo" >"; 
			   }
			   ?>
               
                <option value="1" <?php if ($vartk[$i][$j]==1) { echo"selected='selected'"; } ?> > <?php echo"Sama-sama penting"; ?>
				<option value="3" <?php if ($vartk[$i][$j]==3) { echo"selected='selected'"; } ?> > <?php echo"Sedikit lebih penting"; ?>
				<option value="5" <?php if ($vartk[$i][$j]==5) { echo"selected='selected'"; } ?> > <?php echo" Lebih penting"; ?>
				<option value="7" <?php if ($vartk[$i][$j]==7) { echo"selected='selected'"; } ?> > <?php echo"Sangat penting"; ?>
				<option value="9" <?php if ($vartk[$i][$j]==9) { echo"selected='selected'"; } ?> > <?php echo"Mutlak pentingya"; ?>
				</td>
				<?php } //end for j ?>
              </tr>
			  
<!-- end rasio -->
<?php } echo"<tr><td colspan='6'><div align='right'><input type='submit' value='Proses' name='submit'/></div></td></tr></table>";//end n!=0

//isi bobot kriteria hasilnya didapat berdasarkan pengisian pada perbandingan matriks nya
//echo"<br>TABEL MATRIKS UNTUK KRITERIA<br><br>";
if($N!=0)
{

//echo "<table border='3' align='center'>";

//echo"<tr class='judultable'><td></td>";

for($i=1;$i <= $N;$i++)
{
  //echo"<td>K$i</td>";
}

//echo"</tr>";
$ama=$_POST['a'];
for($i=1;$i <= $N;$i++)
{
  $vari=$_POST['isi'];
  //echo"<tr class='isitabel'><td>K$i</td>";
  for($j=1;$j<=$N;$j++)
  {
     
     echo"<input type='hidden' name='a[$i][$j]' size='5' value="; 
if(!($_POST['a']))
	 {
	    echo" ";
	 }
	 else
	 {
	 if ($i==$j)
	 { 
	    echo"1";
	 }
	 else 
	 {
	   if (($i==$j)or ($i>1 and $j==1) or ($i>=3 and $j==2)or ($i>=4 and $j==3)) echo round(1/$vari[$j][$i],3); else
	    echo round($vari[$i][$j],3);
	 }
	 }
	 echo">";
  }
  //echo"</tr>";
}

//echo"</table>";

?>
<!--end 
//isi bobot kriteria 
<br>TABEL MATRIKS ALTERNATIF UNTUK SETIAP KRITERIA<br><br>-->
<?php
//echo "<br><table border='3' align='center'>";
//buat yg kriteria nya dulu
$kriteria=1;
$i=1;
    //echo"<tr ><td colspan='5'><div align='center'>";
	      while(empty($aform[$kriteria]))
		   {
		       $kriteria++;
			   
		   }
		 
		      //echo ($aform[$kriteria]);
		      $titik=1;
	//echo"</div></td></tr><tr class='judultable'><td></td>";

for($i=1;$i <= 4;$i++)
{
  //echo"<td >A$i</td>";
}
  //echo"</tr>";
 
    

//isi nya disimpen disini  dari proses berdasarkan yg diinput di matriks nya buat isi isi matriks dengan angka 
$labelb=1;
$labelk=1;
$temp=1;
$tuki=1;
$gege=1;
$lancr;
for($i=1;$i <= $N*4;$i++)
{
     
  	 
  //echo"<tr class='isitabel'><td>A$labelk</td>";
  for($j=1;$j<=4;$j++)
  {
     
     echo"<input type='hidden' name='af[$i][$j]' size='5' value='";
	 //echo $alf[$i][$j];
	 //echo $tuki.$j;
if(!($_POST['altj']))
	 {
	    echo" ";
	 }
	 else
	 {
      if ($tuki==$j)
	 { 
	    echo"1";
	 }
	 else 
	 {
	    if($tuki==1)
		{ 
		   $inis=$vartm; 
		   
		}
		else if($tuki==2)
		{ 
		  $inis=$vartp; 
		}
		else if($tuki==3)
		{ 
		  $inis=$varj; 
		}
		else
		{ 
		  $inis=$vartk; 
		}
	    
		/*
		if($j==1)
		{ 
		   $inisb=$vartm; 
		}
		else if($j==2)
		{ 
		  $inisb=$vartp; 
		}
		else if($j==3)
		{ 
		  $inisb=$varj; 
		}
		else 
		{ 
		  $inisb=$vartk; 
		} */
		//$aka="altm".$inis.$tuki;
		//$abe="altj".$inisb.$tuki;
		//echo ("alt".$inis.$temp." alt".$inisb.$temp);
	     if(($inis[$gege][$j])==0)
		 {
		    if($j==1)
			{
			    $lancr=$vartm;
				$mj='tm';
							
			}
			else if ($j==2)
			{
			    $lancr=$vartp;
				$mj='tp';
			}
			else if ($j==3)
			{
				$lancr=$varj;
				$mj='j';
			}
			else if ($j==4)
			{
				$lancr=$vartk;
				$mj='tk';
			}
			 //echo ($mj);
			// echo ($mj.$titik.$tuki);
		   // echo ($mj.$j.$tuki);
		  echo round(1/$lancr[$titik][$tuki],3);
		 }
		 else
		 {
		   echo round($inis[$gege][$j],3);
		 }
		 //echo($gege." ".$j);
		 if($tuki==4 and $j==3)
		 {
		   $gege++;
		   
		  }
		  
	    // echo round($inis[$gege][$j],3);
		 
	 }
}	 
	
	 echo"'>";
	 
  } $tuki++;
  if($tuki>4)
  {
      $tuki=1;
  }
  echo"</tr>";
  if(($i % 4==0) and ($i!=$N*4))
  {
     $kriteria=$kriteria+1;
	 $temp++;
	
     //echo"<tr class='judultable'><td colspan='5'><div align='center'>";
	      while(empty($aform[$kriteria]))
		   {
		       $kriteria++;
			   
		   }
		 
		       //echo ($aform[$kriteria]);
			   $titik++;
		  
	//echo"</div></td></tr><tr class='isitabel'><td></td>";
	 for($u=1;$u <= 4;$u++)
     {
         //echo"<td>A$u</td>";
	 }
  		//echo"</tr>";
  }
    if ($labelk ==4){$labelk=0;}
    $labelk++;  
}
//echo"<tr><td colspan='5'><br></td><tr>";
//echo"<tr><td colspan='5'><div align='right'>";
echo" <div id='jumlah'><input type='submit' value='Cari Rekomendasi' name='submit'/></div>";//</div></td></tr>";
//echo"</table>";


}//akhir dari jika kriteria blum dipilih

//panggil fungsi alernatif

   // echo("<br>Pengisian Bobot alternatif");
  //  alternatif();


/* inisialisasi matriks a b dan c
matriks a : 3 baris, 3 kolom
matriks b : 3 baris, 2 kolom
matriks c : 3 baris, 2 kolom --> hasil kali matriks a dengan b

matriks c terlebih dahulu diinisialisasi nilainya dengan 0
*/
/*
$a[1][1] = 1; $a[1][2] = 2; $a[1][3] = 4;$a[1][4] = 3; $a[1][5] = 5;
$a[2][1] = 1; $a[2][2] = 2; $a[2][3] = 3;$a[2][4] = 2; $a[2][5] = 1;
$a[3][1] = 3; $a[3][2] = 2; $a[3][3] = 0;$a[3][4] = 2; $a[3][5] = 1;
$a[4][1] = 1; $a[4][2] = 2; $a[4][3] = 3;$a[4][4] = 2; $a[4][5] = 1;
$a[5][1] = 3; $a[5][2] = 2; $a[5][3] = 0;$a[5][4] = 2; $a[5][5] = 1;

$b[1][1] = 2; $b[1][2] = 4;
$b[2][1] = 2; $b[2][2] = 2;
$b[3][1] = 1; $b[3][2] = 1;

$c[1][1] = 0; $c[1][2] = 0;
$c[2][1] = 0; $c[2][2] = 0;
$c[3][1] = 0; $c[3][2] = 0;

MULAI HITUNG METODE AHP*/

if(isset($_POST['submit']))
{ 

$jumlahk= $N;// sesuai dengan yg dipilih berdasarkan ceklis di kriteria yg dipilih
$jumlaha= 4*$N;// total alternatif yg akan dicari
$jumlahb= 4;// jumlah alternatif nya

$kondisi1=$kondisi2=1;
for($i=1;$i<=$jumlahk;$i++)
{
   for($j=1;$j<=$jumlahk;$j++)
   {
    	if(empty($ama[$i][$j]))
		{
	   		$kondisi1=2;
	   	
		}
				
	}
}
for($i=1;$i<=$jumlaha;$i++)
{
   for($j=1;$j<=$jumlahb;$j++)
   {
    	if(empty($alf[$i][$j]))
		{
	   		$kondisi2=3;

	   		
		}
				
	}
}
//echo("Kondisi : ".$kondisi);
}
if($kondisi1==1 and $kondisi2==1)
{
$baris_matriks = $N;
$kolom_matriks = $N;


/* inilah loop yang melakukan proses perkalian matriks kriteria */
for ($j = 1; $j <= $kolom_matriks; $j++) {
  for ($i = 1; $i <= $baris_matriks; $i++) {
    for ($k = 1; $k <= $kolom_matriks; $k++) {
      $c[$i][$j] = $c[$i][$j] + ($ama[$i][$k] * $ama[$k][$j]);
    }
  }
}

/*eigen vektor kriteria */

for ($i = 1; $i <= $kolom_matriks; $i++) {
  for ($j = 1; $j <= $baris_matriks; $j++) {
      $eig[$i]=$eig[$i]+$c[$i][$j];
    }
	$tot=$tot+$eig[$i];
  }
for ($i = 1; $i <= $kolom_matriks; $i++) {
   $eigk[$i]=$eig[$i]/$tot;
}
//Hitung kosistensi
//menentukan vektor tertimbang
for ($i = 1; $i <=$N ; $i++) {
  for ($j = 1; $j <= $N; $j++) {
  		$vektor[$i]=$vektor[$i]+$eigk[$j]*$ama[$i][$j];
  }
 }
//menentukan vk
$tot=0;
for ($i = 1; $i <=$N ; $i++) {
  
  		$vk[$i]=$vektor[$i]/$eigk[$i];
		$tot=$tot+$vk[$i];
 }
if($N<=1)
{
    echo "Pilih Kriteria Minimal 2 Kriteria";
}
else
{
$lamda=$tot/$N;
$ik=($lamda-$N)/($N-1);
}
//menentukan IR
if ($N>=1 and $N<=2)
{
	$ir=0;
}
else if($N==3)
{
	$ir=0.58;
}
else if($N==4)
{
	$ir=0.9;
}
else if($N==5)
{
	$ir=1.12;
}
else if($N==6)
{
	$ir=1.24;
}
else if($N==7)
{
	$ir=1.32;
}
else if($N==8)
{
	$ir=1.41;
}
else if($N==9)
{
	$ir=1.45;
}
else if($N==10)
{
	$ir=1.49;
}
if($ir==0)
{
     $rk=0;
}
else
{ 
     $rk=$ik/$ir;
}
//echo("kosistensi ".$rk);

if($rk>0.1)
{
   echo("<br>*) kosistensi ".$rk);
   $ket=("<br>*) Pengisian Penilaian Kriteria TIDAK KONSISTEN <br> Silahkan Masukan Penilaian Untuk Kriteria Kembali...") ;
} 
else
{
// akhir kosistensi
/* inilah loop yang melakukan proses perkalian matriks alternatif untuk setiap kriteria*/
$var=0;
for ($j = 1; $j <= 4; $j++) {
  for ($i = 1; $i <= $N*4; $i++) {

		
    		for ($k = 1; $k <= 4; $k++) {
      			$alter[$i][$j] = $alter[$i][$j] + ($alf[$i][$k] * $alf[$k+$var][$j]);
	
    		}
		if($i%4==0)
		{
		     if($i!=$N*4)
			 {
			 	$var=$var+4;
			 	
			 }
			 else
			 {
			 	$var=0;
			 }	 
		}
		
  }
  
}


/*eigen vektor alternatif */
$tot=0;
$var=1;
for ($i = 1; $i <= $N*4; $i++) {
  for ($j = 1; $j <= 4; $j++) {
      $eiga[$i]=$eiga[$i]+$alter[$i][$j];
    }
	$tot=$tot+$eiga[$i];
	if($i%4==0)
	{
	    $artot[$var]=$tot;
		$tot=0;
		$var++;   
	}
  }
$var=1;
for ($i = 1; $i <= $N*4; $i++) {
   $eigal[$i]=$eiga[$i]/$artot[$var];
   if($i%4==0)
	{
	    $var++;   
	}
}
/* peringkat alternatif */
//bwt matrix peringkat
$var=1;
for ($i = 1; $i <=$N ; $i++) {
  for ($j = 1; $j <= 4; $j++) {
  $perkt[$j][$i]=$eigal[$var];
  $var++;
  }
 }

/* inilah loop yang melakukan proses perkalian matriks peringkat */

$tot=0;
for ($j = 1; $j <= 4; $j++) {
   for ($k = 1; $k <= $N; $k++) {
      $kperkt[$j] = $kperkt[$j] + ($perkt[$j][$k] * $eigk[$k]);
	  
    }
 
  
}



}//akhir pengecekan blum di input
}//akhir cek $N!=0
/* menyusun matriks a dalam bentuk tabel */
$matriks_a = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= $baris_matriks; $i++) {
  $matriks_a .= "<tr>\n";
  for ($j = 1; $j <= $kolom_matriks; $j++) {
    $matriks_a .= "<td>" . $ama[$i][$j] . "</td>";
  }
  $matriks_a .= "</tr>\n";
}
$matriks_a .= "</table>\n";


/* menyusun matriks b dalam bentuk tabel */
$matriks_b = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= $baris_matriks; $i++) {
  $matriks_b .= "<tr>\n";
  for ($j = 1; $j <= $kolom_matriks; $j++) {
    $matriks_b .= "<td>" . $ama[$i][$j] . "</td>";
  }
  $matriks_b .= "</tr>\n";
}
$matriks_b .= "</table>\n";


/* menyusun matriks c dalam bentuk tabel */
$matriks_c = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= $baris_matriks+2; $i++) {
  $matriks_c .= "<tr>\n";
  for ($j = 1; $j <= $kolom_matriks; $j++) {
    $matriks_c .= "<td>" . $perkt[$i][$j] . "</td>";
  }
  
  $matriks_c .= "</tr>\n";
  
}
$matriks_c .= "</table>\n";
/* menyusun matriks alternatif dalam bentuk tabel */
$matriks_alter = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= $N*4; $i++) {
  $matriks_alter .= "<tr>\n";
  for ($j = 1; $j <= 4; $j++) {
    $matriks_alter .= "<td>" . $alter[$i][$j] . "</td>";
  }
  
  $matriks_alter .= "</tr>\n";
  
}
$matriks_alter .= "</table>\n";
//hitung peringkat terbesar
$usaha=$kperkt[1];
$varb=1;
for($i = 2; $i <= 4; $i++) {
    if($usaha < $kperkt[$i])
	{
	    $usaha=$kperkt[$i];
		$varb=$i;
	}
}
/* menyusun eigen peringkat dalam bentuk tabel */
//isi alternatif
$alternatif[1]='Rusunawa / Rusunami';
$alternatif[2]='Tempat Pembuangan Sampah Akhir';
$alternatif[3]='Ruang Terbuka Hijau';
$alternatif[4]='Penampungan Air Bersih';
$alternatif[5]='Septicktank Komunal';
$warna[1]='RED';
$warna[2]='BLUE';
$warna[3]='GREEN';
$warna[4]='ORANGE';
$warna[5]='YELLOW';
//tampilkan hasil perhitungan AHP
$eigenk = "<br><table cellpadding=10 cellspacing=0 border=1 align='center'>\n";
$eigenk .= "<tr><td colspan='2'><div align='center'>Hasil persentasi Jenis Usaha Oleh Sistem </div></td><tr>";
for ($i = 1; $i <= 4; $i++) {
  $eigenk .= "<tr>";
   $eigenk .="<td>".$alternatif[$i]."</td><td>";
  $eigenk .=(round($kperkt[$i],2))*100;
  $eigenk .=" % ";
 
  $eigenk .= "</td></tr>";
  if($i==1)
  {
	  $persen_rusun=(round($kperkt[$i],2))*100;
  }
  if($i==2)
  {
	  $persen_sampah=(round($kperkt[$i],2))*100;
  }
  if($i==3)
  {
	  $persen_hijau=(round($kperkt[$i],2))*100;
  }
  if($i==4)
  {
	  $persen_air=(round($kperkt[$i],2))*100;
  }
  if($i==5)
  {
	  $persen_septitank=(round($kperkt[$i],2))*100;
  }
}

$kriteria=1;
for($i=1;$i <= $N;$i++)
{
    while(empty($aform[$kriteria]))
		   {
		       $kriteria++;
			   
		   }
		 		if($aform[$kriteria]=="penduduk"){
		       $pil_kriteria1 = $kriteria;
				}
		 		if($aform[$kriteria]=="omset"){
		       $pil_kriteria2 = $kriteria;
				}
		 		if($aform[$kriteria]=="jumlah_usaha"){
		       $pil_kriteria3 = $kriteria;
				}
		 		if($aform[$kriteria]=="luas_kec"){
		       $pil_kriteria4 = $kriteria;
				}
			   $kriteria++;
}
$eigenk .= "<tr><td>kosistensi </td><td>".round($rk*100,3)." %";
$eigenk .= "<tr><td colspan='2'>Untuk melihat rekomendasi di kabupaten ".$_SESSION['nama_kab']."
                    klik <a href='rekomendasi.php?ahpdat=$_SESSION[nama_kab]|$persen_rusun|$persen_sampah|$persen_hijau|$persen_air|$persen_septitank|$pil_kriteria1|$pil_kriteria2|$pil_kriteria3|$pil_kriteria4|$varb'> disini ............</a></font></div></td></tr>";
$eigenk .= "</table>\n";
/* menyusun bobot kriteria */
$kbobot = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= $baris_matriks+2; $i++) {
  $kbobot .= "<tr>\n <td>";
  $kbobot .=$vk[$i];
  
  $kbobot .= "</td></tr>\n";
  
}


$kbobot .= "</table>\n";
/* menyusun jumlah kolom alternatif */
$jeigenalt = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= $N*4; $i++) {
  $jeigenalt .= "<tr>\n <td>";
  $jeigenalt .=$eiga[$i];
  
  $jeigenalt .= "</td></tr>\n";
  
}
$jeigenalt .= "</table>\n";

/* menyusun eigen kriteria */
$eigenalt = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= 4; $i++) {
  $eigenalt .= "<tr>\n <td>";
  $eigenalt .=$eigk[$i];
  
  $eigenalt .= "</td></tr>\n";
  
}
$eigenalt .= "</table>\n";
/* menyusun eigen alternatif */
$accoe = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= $N*4; $i++) {
  $accoe .= "<tr>\n <td>";
  $accoe .=$eigal[$i];
  $accoe .= "</td></tr>\n";
  
}

$accoe .= "</table>\n";

/* menyusun testing perkalian kriteria*/
$cco = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= 4; $i++) {
$cco .= "<tr>";
for ($j = 1; $j <= 4; $j++) {
  $cco .= "<td>";
  $cco .=$c[$i][$j];
  $cco .= "</td>";
  }
  $cco .= "</tr>";
  
}
$cco .= "</table>\n";
/* menyusun testing matrix kriteria*/
$ccop = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= 4; $i++) {
$ccop .= "<tr>";
for ($j = 1; $j <= 4; $j++) {
  $ccop .= "<td>";
  $ccop .=$perkt[$i][$j];
  $ccop .= "</td>";
  }
  $ccop .= "</tr>";
  
}
$ccop .= "</table>\n";

/* menyusun testing perkalian alternatif*/
$aco = "<table cellpadding=10 cellspacing=0 border=1>\n";
for ($i = 1; $i <= $N*4; $i++) {
$aco .= "<tr>";
for ($j = 1; $j <= 4; $j++) {
  $aco .= "<td>";
  $aco .=$alter[$i][$j];
  $aco .= "</td>";
  }
  $aco .= "</tr>";
  
}
$aco .= "</table>\n";
/* for ($i = 1; $i <= $N; $i++) {
   echo("totna : ".$artot[$i] );
}
 tampilkan halaman dalam format html,
yang sudah berisi matriks a b dan c */

}//akhir else konsistensi
echo ($ket);

if($kondisi1==1 and $kondisi2==1 and $rk<0.1)
{
echo ($eigenk);
}
else
{
   if($kondisi1==2 and $kondisi2==3)
   {
      echo" <br>*)Penilaian Kriteria Belum Diisi Lengkap";
   }
   if($kondisi2==3)
   {
      echo" <br>*)Penilaian Alternatif Belum Diisi Lengkap";
   }

}
//echo"<input type='hidden' name='ditx' value=$params[1] >"; 
//echo ("param : ".$_SESSION['namak']) 
if($_POST['submit']=="pilih")
{
   echo "OK";
}

?>